package distributedbank;

import java.io.IOException;

import distributedbank.gui.BranchGui;
import distributedbank.server.BankBranch;

public class Main {

    // if set to true, there is a 5-second delay before TransferDeposit messages
    // are sent
    public static boolean doDelayTransfers = false;

    public static boolean doDelaySnapshots = false;

    /**
     * USAGE 1: java distributedbank.Main client 1
     * 
     * USAGE 2: java distributedbank.Main server 1
     * 
     * Where "1" should be replaced by the desired branchId for the process.
     * Decides whether to run the BranchGui or the BankBranch main() method,
     * depending on the first argument.
     * 
     * @throws ClassNotFoundException
     */
    public static void main(String[] args) throws IOException,
            ClassNotFoundException {
        // if (args.length == 3 && args[2].equals("-delay")) {
        // Main.doDelayTransfers = true;
        // args = new String[] { args[0], args[1] };
        // } else if (args.length == 3 && args[2].equals("-delay-snapshots")) {
        // Main.doDelayTransfers = true;
        // Main.doDelaySnapshots = true;
        // args = new String[] { args[0], args[1] };
        // }

        if (args[0].equals("client")) {
            BranchGui.main(new String[] { args[1] });
        } else if (args[0].equals("server")) {
            BankBranch.main(new String[] { args[1], args[2] });
        } else if (args[0].equals("oracle")) {
            Oracle.main(new String[0]);
        } else {
            System.out
                    .println("USAGE: %program {oracle|client|server} BRANCH_NUMBER [REPLICA_NUMBER]");
            System.exit(1);
        }
    }
}
